package com.atguigu.gmall.scheduled.jdk;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: 86182
 * @Date: 2021/8/22
 * @Time: 22:29
 * @Version:
 */
public class ScheduledDeomo {
    public static void main(String[] args) {
        System.out.println("定时任务初始化时间: " + System.currentTimeMillis());
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);
        scheduledExecutorService.scheduleAtFixedRate(()->{
            System.out.println("这是一个通过线程池初始化了一个定时任务" + System.currentTimeMillis());
        },5,10, TimeUnit.SECONDS);


//        new Timer().schedule(new TimerTask() {
//            @Override
//            public void run() {
//                System.out.println("这是一个通过定时器初始化了一个定时任务: " + System.currentTimeMillis());
//            }
//        },5000,10000);
    }
}
